#ifndef BOARDCLIENT_H
#define BOARDCLIENT_H

#include <QObject>
#include <QMutex>
#include "ctrl_reg.h"

class QTimer;
class QTcpSocket;
class BoardClient : public QObject
{
    Q_OBJECT

public:
    BoardClient(QObject *parent = nullptr);
    ~BoardClient();
signals:
    void sendData(QByteArray &data);
private:
    void onCameraPowerOn();
    void initialTime();
    void onScanServer();
    void OnReadData();
    void onWritData(const QByteArray &data);
    void onCommandParse();
    void onHeartbeat();
    QList<QByteArray> GetListCommands();
    bool checkRecvCommand(const QByteArray &cmd);
    void SetListCommands(QList<QByteArray> array);

    void restartCamera(quint16 frame, QByteArray data);
    void externalTrigger(quint16 frame);
    void metryLight(quint16 frame);
private:
    int num = 0;
    unsigned int electricity_ = 16777215;
    int device_num_ = 25;
    QString serverIp = "169.254.101.100";
    quint16 serverPort = 9999;
    int nTimeOut = 500;
    QTcpSocket* socket = nullptr;
    QTimer *timer = nullptr;//检测是否连接
    QTimer *command_timer = nullptr;//定时读取指令
    QTimer *heartbeat_timer = nullptr;//心跳，用来触发检测连接
    QTimer *start_timer = nullptr;//

    QMutex mutex;
    QByteArray lastRemainData;
    QList<QByteArray> listBuffers;
    QTimer *trigger_timer_ = nullptr;

    static unsigned int GPIO0_BASE_ADDR;
    gpio_handle handle_gpio0;
};
#endif // BOARDCLIENT_H
